package com.medical.admin.hospital.controller;

import com.medical.admin.cost.common.dto.DoctorDto;
import com.medical.admin.hospital.common.vo.*;
import com.medical.admin.hospital.service.ComboService;
import com.medical.admin.hospital.service.DepartmentService;
import com.medical.admin.hospital.service.DoctorService;
import com.qf.medical.ex.BaseException;
import com.qf.medical.response.ResponseCode;
import com.qf.medical.response.ResponseEntity;
import com.qf.medical.up.aliyun.AliOSSUtilsAutoConfiguration;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;
/**
 * @description: 医生信息管理
 * @author: LuAn
 * @date: 2024/4/29
 */
@Api(tags = "医生管理信息在线文档")
@RestController
@RequestMapping("/doctor")
public class DoctorController {

    @Resource
    private DoctorService doctorService;

    @Resource
    private AliOSSUtilsAutoConfiguration aliOSSUtilsAutoConfiguration;

    @Resource
    private ComboService comboService;

    @Resource
    private DepartmentService departmentService;


    @GetMapping("/page")
    @ApiOperation("分页查询医生信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "departmentName",value = "科室名称"),
            @ApiImplicitParam(name = "doctorName", value = "医生名称"),
            @ApiImplicitParam(name = "pageNum",value = "当前页"),
            @ApiImplicitParam(name = "pageSize",value = "页大小")})
    public ResponseEntity<PageVo<DoctorDto>> list(String departmentName, String doctorName, @RequestParam(defaultValue = "1")
    int pageNum, @RequestParam(defaultValue = "10") int pageSize){
        return ResponseEntity.success(doctorService.list(departmentName,doctorName,pageNum,pageSize));
    }

    @PostMapping("/add")
    @ApiOperation("新增医生信息")
    @ApiImplicitParam(name = "doctorDto",value = "医生信息")
    public ResponseEntity<ResponseCode> add(@RequestBody DoctorDto doctorDto){
        doctorService.insert(doctorDto);
        return ResponseEntity.success(ResponseCode.DOCTOR_INFO_UPDATE_SUCCESS);
    }

    @ApiOperation("修改医生信息")
    @PutMapping("/modify")
    @ApiImplicitParam(name = "doctorDto" ,value = "医生信息")
    public ResponseEntity<Integer> modify(@RequestBody DoctorDto doctorDto){
        return ResponseEntity.success(doctorService.update(doctorDto));
    }

    @ApiOperation("删除医生信息")
    @DeleteMapping("/remove")
    @ApiImplicitParam(name = "doctorId" ,value = "医生ID")
    public ResponseEntity<Integer> remove(@NotNull Long doctorId){
        return ResponseEntity.success(doctorService.delete(doctorId));
    }

    @ApiOperation("查询医生详情")
    @GetMapping("/detail")
    @ApiImplicitParam(name = "doctorId" ,value = "医生ID")
    public ResponseEntity<DoctorVo> detail(@NotNull Long doctorId){
        return ResponseEntity.success(doctorService.select(doctorId));
    }


    @PostMapping("/upload")
    @ApiOperation("医生信息图片上传")
    @ApiImplicitParam(name = "file",value = "文件上传对象")
    public String upload(@NotNull MultipartFile file) {
        try {
            return aliOSSUtilsAutoConfiguration.upload(file);
        } catch (IOException e) {
            throw  new BaseException(ResponseCode.SYS_ERROR);
        }
    }

    @ApiOperation("下拉展示科室一级信息")
    @GetMapping("/showParent")
    public ResponseEntity<List<DepartmentVo>> showParent(){
        return ResponseEntity.success(departmentService.showParent());
    }

    @ApiOperation("下拉展示科室二级信息")
    @GetMapping("/showDetail")
    @ApiImplicitParam(name = "parentId",value = "上级目录")
    public ResponseEntity<DepartmentVo> showDepartments(@RequestParam(defaultValue = "1") Long parentId){
        return ResponseEntity.success(departmentService.showDepartments(parentId));
    }

    @ApiOperation("下拉展示医院信息")
    @GetMapping("/showHospital")
    public ResponseEntity<DownMenu> showHospital(){
        return ResponseEntity.success(comboService.selectHospital());
    }

    @ApiOperation("下拉展示医生职称")
    @GetMapping("/showTitle")
    public ResponseEntity<DownMenu> showTitle(){
        return ResponseEntity.success(doctorService.findTitleName());
    }
}
